<template>
    <keep-alive>
        <v3-crud ref="pagecrud" :schema="config" :hooks="hooks" @event="handleEvent"></v3-crud>
    </keep-alive>
    
</template>
<script setup>
import config from './config'
import v3Crud from '../components/index.vue'
import { reactive, ref } from 'vue';
import { onMounted } from 'vue';
const pagecrud = ref(null)
console.log('pagecrud----', pagecrud);
const arr = {
    /* size: 1, current: 1, total: 12, data:
    [
        {"name": "张三", "age": 18, 'phone': '12345678901', 'address': '北京市', 'status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "李四", "age": 20, 'phone': '12345678902', 'address': '上海市','status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "王五", "age": 22, 'phone': '12345678903', 'address': '广州市','status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "张三", "age": 18, 'phone': '12345678901', 'address': '北京市', 'status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "李四", "age": 20, 'phone': '12345678902', 'address': '上海市','status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "王五", "age": 22, 'phone': '12345678903', 'address': '广州市','status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "张三", "age": 18, 'phone': '12345678901', 'address': '北京市', 'status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "李四", "age": 20, 'phone': '12345678902', 'address': '上海市','status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "王五", "age": 22, 'phone': '12345678903', 'address': '广州市','status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "张三", "age": 18, 'phone': '12345678901', 'address': '北京市', 'status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "李四", "age": 20, 'phone': '12345678902', 'address': '上海市','status': 'active', 'createTime': '2023-06-01 10:00:00'},
        {"name": "王五", "age": 22, 'phone': '12345678903', 'address': '广州市','status': 'active', 'createTime': '2023-06-01 10:00:00'},
    ], */
}
onMounted(() => {
    pagecrud.value.updateTableData({}, arr)
    // operateOnComponent()
    // 模拟数据更新
    /* setTimeout(() => {
        pagecrud.value.updateTableData({}, {size: 1, current: 1, total: 1, data: [{
            "name": "李四", "age": 20, 'phone': '12345678902', 'address': '上海市','status': 'active', 'createTime': '2023-06-01 10:00:00'
        }]})
    }, 2000) */
})
const handleEvent = (event, data) => {
    console.log('event--', event, data)
    pagecrud.value.closeDialog(data)
}
const test = (a,b,c) => {
    console.log('test----a,b,c', a,b,c)
}
const hooks = {
  edit: async (obj) => {
      console.log('edit--', obj)
      updateTableData().then(() => {
          pagecrud.value.closeDialog(obj.data)
      })
  },
  add: async (obj) => {
      console.log('add--', obj)
      console.log('a--', a)
      if (a) ElMessage({
          message: '添加失败！请查看数据录入要求！',
          type: 'error',
      });
  },
  del: async (obj) => {
      console.log('del--', obj)
      updateTableData()
  },
  get: async (obj) => {
      console.log('get--', obj)
      condition = obj.data
  },
  detail: async (obj) => {
      console.log('detail--', obj)
  },
}
defineExpose({
    handleEvent, test
})
</script>